from rest_framework.serializers import ModelSerializer

from apps.users.models import User


class UserModelSerializer(ModelSerializer):
    class Meta:
        model = User

        fields = ['id', 'username', 'mobile', 'email', 'password']

    def create(self, validated_data):
        """
        重写create方法创建加密密码的用户
        :param validated_data:
        :return:
        """
        user = User.objects.create_user(**validated_data)

        return user
